package ewms.controller;

import java.util.List;
import java.util.Arrays;

import ewms.bo.EwmsWasteCollectAddBo;
import ewms.bo.EwmsWasteCollectEditBo;
import ewms.bo.EwmsWasteCollectQueryBo;
import ewms.service.IEwmsWasteCollectService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import ewms.common.annotation.RepeatSubmit;
import ewms.common.annotation.Log;
import ewms.common.core.controller.BaseController;
import ewms.common.core.domain.AjaxResult;
import ewms.common.enums.BusinessType;
import ewms.vo.EwmsWasteCollectVo;
import ewms.common.utils.poi.ExcelUtil;
import ewms.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 危废收运Controller
 *
 * @author zhaoxiaochun
 * @date 2022-01-26
 */
@Api(value = "危废收运控制器", tags = {"危废收运管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/wasteCollect")
public class EwmsWasteCollectController extends BaseController {

    private final IEwmsWasteCollectService iEwmsWasteCollectService;

    /**
     * 查询危废收运列表
     */
    @ApiOperation("查询危废收运列表")
    @PreAuthorize("@ss.hasPermi('business:wasteCollect:list')")
    @GetMapping("/list")
    public TableDataInfo<EwmsWasteCollectVo> list(@Validated EwmsWasteCollectQueryBo bo) {
        return iEwmsWasteCollectService.selectPageWasteCollectList(bo);
    }

    /**
     * 导出危废收运列表
     */
    @ApiOperation("导出危废收运列表")
    @PreAuthorize("@ss.hasPermi('business:wasteCollect:export')")
    @Log(title = "危废收运", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EwmsWasteCollectVo> export(@Validated EwmsWasteCollectQueryBo bo) {
        List<EwmsWasteCollectVo> list = iEwmsWasteCollectService.selectWasteCollectList(bo);
        ExcelUtil<EwmsWasteCollectVo> util = new ExcelUtil<EwmsWasteCollectVo>(EwmsWasteCollectVo.class);
        return util.exportExcel(list, "危废收运");
    }

    /**
     * 获取危废收运详细信息
     */
    @ApiOperation("获取危废收运详细信息")
    @PreAuthorize("@ss.hasPermi('business:wasteCollect:query')")
    @GetMapping("/{wasteCollectId}")
    public AjaxResult<EwmsWasteCollectVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("wasteCollectId") Long wasteCollectId) {
        return AjaxResult.success(iEwmsWasteCollectService.queryById(wasteCollectId));
    }

    /**
     * 新增危废收运
     */
//    @ApiOperation("新增危废收运")
//    @PreAuthorize("@ss.hasPermi('business:wasteCollect:add')")
//    @Log(title = "危废收运", businessType = BusinessType.INSERT)
//    @RepeatSubmit
//    @PostMapping()
//    public AjaxResult<Void> add(@Validated @RequestBody EwmsWasteCollectAddBo bo) {
//        return toAjax(iEwmsWasteCollectService.insertByAddBo(bo) ? 1 : 0);
//    }

	/**
	 * 危废收运
	 */
	@ApiOperation("危废收运")
	@PreAuthorize("@ss.hasPermi('business:wasteCollect:collect')")
	@Log(title = "危废收运", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> collect(@Validated @RequestBody EwmsWasteCollectAddBo bo) {
		return toAjax(iEwmsWasteCollectService.collectByAddBo(bo) ? 1 : 0);
	}

    /**
     * 修改危废收运
     */
    @ApiOperation("修改危废收运")
    @PreAuthorize("@ss.hasPermi('business:wasteCollect:edit')")
    @Log(title = "危废收运", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody EwmsWasteCollectEditBo bo) {
        return toAjax(iEwmsWasteCollectService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 撤回危废收运
     */
    @ApiOperation("撤回危废收运")
    @PreAuthorize("@ss.hasPermi('business:wasteCollect:remove')")
    @Log(title = "危废收运" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{wasteCollectDetailIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] wasteCollectDetailIds) {
    	if (wasteCollectDetailIds.length == 0){
    		return AjaxResult.error("请选择至少一条要撤回的记录");
		}
        return toAjax(iEwmsWasteCollectService.deleteWithValidByIds(Arrays.asList(wasteCollectDetailIds), true) ? 1 : 0);
    }
}
